<%@tag pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<style>
<!--
.duihao {
	width: 25px;
	height: 25px;
	position: absolute;
	top: 0px;
	right: 0px;
	background: url(${ctx}/static/images/checkSmall.gif) no-repeat;
	background-position: 0px 0px;
}
-->
</style>
<script type="text/javascript">


	//根据快递单模版的Id与后台交互
	function selectAjaxPreview(temp) {
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/selectAjaxDesign',
			data : 'expressStyleId=' + temp,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					DisplayPreview(data.name, data.content, data.width,data.height);
				} else if (data.status == "0") {
					alert("加载出错！！！");
				}
			},
			error : function() {
				alert("加载出错！！！");
			}
		});
	}
	//打印预览
	function DisplayPreview(name, temp, width, height) {
		LODOP = getLodop(document.getElementById('LODOP'), document
				.getElementById('LODOP_EM'));
		LODOP.PRINT_INIT(name);
		LODOP.SET_PRINT_PAGESIZE(1, width, height, "");
		eval(temp);
		LODOP.SET_SHOW_MODE("BKIMG_PRINT", 1);
		LODOP.PREVIEW();
	};

	function checkBoxChange(id, item) {
	    var fa=item.checked;
		if (!fa) {
			if (!confirm("是否确认取消默认！")) {
				$("#checkBox_" + id).attr("checked", true);
			} else {
				$.ajax({
					type : 'post',
					url : '${ctx}/v2/expressPrinting/cancelDefault',
					data : 'expressStyleId=' + id,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							alert("取消成功请马上设置新的默认快递单！");
							$("#duihao_"+id).removeClass("duihao"); 
						} else if (data.status == "0") {
							alert("取消失败!");
							$("#checkBox_" + id).attr("checked", true);
						}
					},
					error : function() {
						alert("取消失败!");
						$("#checkBox_" + id).attr("checked", true);
					}
				});
			}
		} else {
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/expressPrinting/addDefault',
				data : 'expressStyleId=' + id,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						alert("设置默认成功");
						$("#duihao_"+id).addClass("duihao");
						$("#checkBox_" + id).attr("checked", true);
						
						//$("#duihao_"+id).attr("style","width: 25px;height: 25px;position: absolute;top: 0px;right: 0px;background: url(${ctx}/static/images/checkSmall.gif) no-repeat;background-position: 0px 0px;");
					} else if (data.status == "0") {
						alert("设置默认失败!");
						$("#checkBox_" + id).attr("checked", false);
					} else if (data.status == "-1") {
						alert("该组已经存在默认快递单!");
						$("#checkBox_" + id).attr("checked", false);
					}
				},
				error : function() {
					alert("设置默认失败!");
					$("#checkBox_" + id).attr("checked", false);
				}
			});
		}
	}

	function companyAjaxExpressStyle(flg) {
		if(flg){
			
		}else{
			flg="companyAjaxExpressStyle";
		}
		var tempString = "";
		$("#jsonContent").html(tempString);
		$
				.ajax({
					type : 'post',
					//url : '${ctx}/v2/expressPrinting/companyAjaxExpressStyle',
					url : '${ctx}/v2/expressPrinting/'+flg,
					data : 'logisticsCompanys=' + $("#logisticsCompanys").val()+'&areaGroupCode='+$("#areaGroups").val()+'&cainiaoFlg='+$("#cainiaoFlg").val()+'&customerCode='+$("#customerCode").val(),
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							tempString = "<div class=\"row\">";
							$
									.each(
											data.content,
											function(i) {
												tempString +=  "<div class=\"col-md-3\">";
												tempString +=  "<div class=\"box box-primary\">";
												tempString +=  "<div class=\"box-header\" data-toggle=\"tooltip\">";
												tempString +=  "<i class=\"fa fa-user\"></i>";
												tempString +=  "<h3 class=\"box-title\">"+data.content[i].customerName+"</h3>";
												tempString +=  "</div>";
												tempString +=  "<div class=\"box-body\">";
												tempString +=  "<div class=\" row center \">";
												tempString +=  "<div class=\"col-md-12\">";
												if (data.content[i].styleDefault == 1) {
													tempString += "<div style=\"position: relative;\"><div class=\"duihao\" id=\"duihao_"+data.content[i].id+"\"></div>";
												} else {
													tempString += "<div style=\"position: relative;\"><div class=\"\" id=\"duihao_"+data.content[i].id+"\"></div>";
												}
												tempString += "<img src=\""+data.content[i].styleImageUrl+"\" data-src=\"holder.js/120x160\" alt=\"120x160\" style=\"width:300px; height: 160px;\" class=\"img-thumbnail\">";
												tempString +=  "</div>";
												tempString +=  "<div class=\"col-md-12 margin-top-10\">";
												/*if (data.content[i].styleDefault == 1) {
													tempString += "<input type=\"checkbox\" id=\"checkBox_"
															+ data.content[i].id
															+ "\" onchange=\"checkBoxChange("
															+ data.content[i].id
															+ ",this)\" checked=\"true\"></input>设置为默认";
												} else {
													tempString += "<input type=\"checkbox\" id=\"checkBox_"
															+ data.content[i].id
															+ "\" onchange=\"checkBoxChange("
															+ data.content[i].id
															+ ",this)\"></input>设置为默认";
												}*/

												if (data.content[i].type == "mail") {
													tempString +=  "<h5>快递单类型：电子面单</h5><p>";
												} else {
													tempString +=  "<h5>快递单类型：普通面单</h5><p>";
												}
												tempString += "<h5>快递单名称："
														+ data.content[i].styleName
														+ "</h5><p>";
												tempString += "<h5>商家："
														+ data.content[i].customerName
														+ "</h5><p>";
														
												tempString += "<h5>网点："
														+ data.content[i].areaGroupCode
														+ "</h5><p>";
       									tempString +="</div>";    
       									tempString +="</div>";    
       									tempString +="</div>";    
										tempString +="<div class=\"box-footer clearfix\">";
										tempString +="<div class=\"box-tools \">";
												tempString = tempString
														//+ "<a class=\"btn btn-success pull-left\" href=\"javascript:selectAjaxPreview("+data.content[i].id+")\">预览</a>"
														+ "<a class=\"btn btn-success pull-left\" href=\"${ctx}/v2/expressPrinting/updataExpressStyle/"+data.content[i].id+"\">修改</a>"
														+ "<a class=\"btn btn-danger pull-right\" href=\"javascript:DeleteExpress("+data.content[i].id+");\">删除</a>";
       									tempString +="</div>";    
       									tempString +="</div>";    
       									tempString +="</div>";    
       									tempString +="</div>";    
       									tempString +="</div>";    
											});
							tempString += "</div>";
							$("#jsonContent").html(tempString);
						} else if (data.status == "-1") {
							//alert("您还没有设计这个快递公司的快递单！");
							tempString = "<h4>您还没有设计这个快递公司的快递单！</h4>";
							$("#jsonContent").html(tempString);
						}
					},
					error : function() {

					}
				});
	}
	function DeleteExpress(id) {
		jConfirm("您确认要删除该模板吗?","温馨提示",function(r){
			if(r){
				//window.location.href = "${ctx}/v2/expressPrinting/deleteExpress/" + id;
				//window.location.href = "${ctx}/v2/expressPrinting/deleteExpress/" + id+"?"+'logisticsCompanys=' + 
				//$("#logisticsCompanys").val()+'&areaGroupCode='+$("#areaGroups").val()+'&cainiaoFlg='+$("#cainiaoFlg").val()+'&customerCode='+$("#customerCode").val();
				companyAjaxExpressStyle("deleteExpressNew/" + id);
			}
		});
	}
	$(function() {
		$("#submit_normal").click(
				function() {
					$("#myFormId").attr( "action", "${ctx}/v2/expressPrinting/addExpress/" + $("#logisticsCompanys").val()+"/normal/0");
					$("#myFormId").submit();
				});
		$("#submit_mail").click(
				function() {
					$("#myFormId").attr( "action", "${ctx}/v2/expressPrinting/addExpress/" + $("#logisticsCompanys").val()+"/mail/0");
					$("#myFormId").submit();
				});
		$("#submit_cainiao").click(
				function() {
					$("#myFormId").attr( "action", "${ctx}/v2/expressPrinting/addExpress/" + $("#logisticsCompanys").val()+"/mail/1");
					$("#myFormId").submit();
				});
	});
</script>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">查询条件</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
<div class="box-body">				
<form action="" id="myFormId" class="form-horizontal">
	
<div class="form-group row">

		<div class="col-sm-3">
			<div class="input-group col-sm-12">
				<span class="input-group-text"> 网点：</span> 
				<select id="areaGroups" class="form-control"  name="areaGroups" onchange="companyAjaxExpressStyle()">
					<c:forEach items="${areaGroups}" var="obj">
						<option value="${obj.groupCode}"
							<c:if test="${areaGroupCode eq obj.groupCode}">selected="selected"</c:if>>
							${obj.groupName}
						</option>
					</c:forEach>
				</select>
			</div>
		</div>
		
		<div class="col-sm-3">
			<div class="input-group col-sm-12">
				<span class="input-group-text"> 物流公司：</span> 
				<select id="logisticsCompanys" class="form-control" name="logisticsCompanyId" onchange="companyAjaxExpressStyle()">
					<c:forEach items="${logisticsCompanys}" var="logisticsCompany">
						<option value="${logisticsCompany.id}"
							<c:if test="${logisticsCompany.id eq logisticsCompanyItem.id}">selected="selected"</c:if>>
							${logisticsCompany.companyName}
						</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="col-sm-3">
			<div class="input-textgroup col-sm-12">
				<span class="input-group-text"> 商家： </span> 
				<select data-placeholder="请选择..." class="form-control searchSelect" id="customerCode" onchange="companyAjaxExpressStyle()">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
							<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
					</c:forEach>
				</select>
			</div>
		</div>	
		<div class="col-sm-3">
			<div class="input-group col-sm-12">
				<span class="input-group-text"> 是否菜鸟：</span> 
				<select id="cainiaoFlg" class="form-control" name="cainiaoFlg" onchange="companyAjaxExpressStyle()">
					<option value="0">否</option>
					<option value="1">是</option>
				</select>
			</div>
		</div>
		</div>
		<div class="form-group row">
			<div class="col-sm-6">
				<input id="submit_normal" class="btn btn-primary" type="submit" value="增加普通快递单" />
				<input id="submit_mail" class="btn btn-primary" type="submit" value="增加电子面单模板" />
				<input id="submit_cainiao" class="btn btn-primary" type="submit" value="增加菜鸟面单模板" />
			</div>
		</div>
</form>	
</div>
</div>
</div>
</div>

<script type="text/javascript">
	companyAjaxExpressStyle();
</script>
<div class="form-group row">
			<div class="col-md-12">
				<div class="box box-solid box-primary">
					<div class="box-header">
						<i class="fa fa-list"></i>
						<h3 class="box-title">快递单列表</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">
<div id="jsonContent"></div>
</div>
</div>
</div>
</div>
</section>